package com.corpgovernment.common.enums;

import com.google.common.collect.Lists;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;

/**
 * 重试枚举
 */
public enum RetryInspectEnum {
    TICKET_ERROR_v1("10401302", "身份验证失败"),
    TICKET_EXPIRE_v1("10401304", "身份过期，请重新生成Ticket"),
    TICKET_NUM_EXPIRE_v1("10401305", "身份验证次数过期，请重新生成Ticket"),
    TICKET_ERROR_v2("302", "身份验证失败"),
    TICKET_EXPIRE_v2("304", "身份过期，请重新生成Ticket"),
    TICKET_NUM_EXPIRE_v2("305", "身份验证次数过期，请重新生成Ticket"),

    ;

    RetryInspectEnum(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    @Getter
    private String code;

    @Getter
    private String msg;

    public static RetryInspectEnum getByCode(String code) {
        return Arrays.stream(RetryInspectEnum.values()).filter(e -> code.equals(e.code)).findFirst().orElse(null);
    }

    /**
     * 获取Ticket异常的errorCode
     * @return
     */
    public static List<String> getTicketErrorCodeList() {
        return Lists.newArrayList(TICKET_ERROR_v1.getCode(), TICKET_EXPIRE_v1.getCode(), TICKET_NUM_EXPIRE_v1.getCode(),
            TICKET_ERROR_v2.getCode(), TICKET_EXPIRE_v2.getCode(), TICKET_NUM_EXPIRE_v2.getCode());
    }
}